<?php 
	//FOR DEBUGGING--comment out when done!
	ini_set('display_errors', 1);
	ini_set('error_reporting', E_ALL ^ E_NOTICE);
	error_reporting(1);

	session_start();
	
	include('../includes/db_connect.php'); 
	//include('../includes/phpheader.php');
$id = $_POST["id"];
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
//added 2008-08-08
$mInitial       								=$_POST["mInitial"];
$social_security_number  =$_POST["social_security_number"];
$medicaid_number       			=$_POST["medicaid_number"];
$medicare_number       			=$_POST["medicare_number"];
$county       										=$_POST["county"];

$query = "SELECT id FROM consumer WHERE id = ".$id;
if($row = mysql_fetch_array(mysql_query($query))) {
	$query = "UPDATE consumer 
								SET first_name = '".$fName."', 
										 last_name = '".$lName."', 
										 middle_initial = '".$mInitial."', 
										 ssn = '".$social_security_number."', 
										 medicaid = '".$medicaid_number."', 
										 medicare = '".$medicare_number."', 
										 address = '".$address."', 
										 city = '".$city."',
											county = '".$county."', 										 
										 state_id = ".$state.", 
										 zip = '".$zip."', 
										 phone = '".$phone."' 
								WHERE id=".$id;
	$status = "This file was updated successfully.";
} else {
	
	/*$query = "SELECT max(id)+1 
			      AS id 
			    FROM consumer";
	$row = mysql_fetch_array(mysql_query($query));
	*/
	$r = mysql_query("SHOW TABLE STATUS LIKE 'consumer' ");
	$row = mysql_fetch_array($r);
	$next_id = $row['Auto_increment'];
	mysql_free_result($r);
	
	$id = $next_id;
	$query = "INSERT INTO consumer(id, 
										   first_name, 
										   last_name, 
										   middle_initial, 
										   ssn, 
										   medicaid, 
										   medicare, 
										   address, 
										   city, 
										   county, 
										   state_id, 
										   zip, 
										   phone) 
				VALUES(".$id.",
						   '".$fName."', 
						   '".$lName."', 
						   '".$mInitial."', 
						   '".$social_security_number."', 
						   '".$medicaid_number."', 
						   '".$medicare_number."', 
						   '".$address."', 
						   '".$city."', 
						   '".$county."',
						   ".$state.", 
						   '".$zip."', 
						   '".$phone."');";
	$status = "The new case file was successfully created.";
}
if(mysql_query($query)) {
  header("Location:../admin.php?action=cieedit&id=".$id."&Status=".$status);
  exit();
} else {
	//echo "Failure <br/>".$query.mysql_error();
  header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to update consumer due to system error.  Please contact system administrator.");
  //echo "Failure <br/>".$query;  
  exit();
}
?>